package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.Jbqk;
import com.corpcredit.model.Zykhxx;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class ZykhxxForm extends BasePage implements Serializable {
    private GenericManager<Zykhxx, Long> zykhxxManager;
    private Zykhxx zykhxx = new Zykhxx();
    private Long id;
    private Jbqk jbqk;

    public void setJbqk( Jbqk jbqk )
    {
        this.jbqk = jbqk;
    }
    public void setZykhxxManager(GenericManager<Zykhxx, Long> zykhxxManager) {
        this.zykhxxManager = zykhxxManager;
    }

    public Zykhxx getZykhxx() {
        return zykhxx;
    }

    public void setZykhxx(Zykhxx zykhxx) {
        this.zykhxx = zykhxx;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        zykhxxManager.remove(zykhxx.getId());
        addMessage("zykhxx.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            zykhxx = zykhxxManager.get(id);
        } else {
            zykhxx = new Zykhxx();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (zykhxx.getId() == null || zykhxx.getId() == 0);
        // set the related jbqk as a foreign key.
        zykhxx.setJbqk( jbqk );
        zykhxxManager.save(zykhxx);

        String key = (isNew) ? "zykhxx.added" : "zykhxx.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
} 